#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using L = vector<vector<int>>;

void addEdge(L &graph, int u, int v) {
    graph[u].push_back(v);
}
vector<int> kahn(L &graph) {
    int n = graph.size();
    vector<int> in(n);
    vector<int> r;
    for(int i=0;i<n;i++){
        for(int &e : graph[i]){
            in[e]++;
        }
    }
    queue<int> q;
    for(int i=0;i<n;i++){
        if(in[i] == 0){
            q.push(i);
        }
    }
    while (!q.empty()) {
        int a = q.front();
        q.pop();
        r.push_back(a);
        for(int &e : graph[a]){
            in[e]--;
            if(in[e] == 0){
                q.push(e);
            }
        }
    }
    if(r.size() != n){
        vector<int>err;
        return err;
    }
    return r;
}
int main(){
    int n;
    cin>>n;
    L graph(n);
    int u,v;
    while(!cin.eof()){
        cin>>u>>v;
        addEdge(graph,u,v);
    }
    vector<int> res=kahn(graph);
    if(res.empty()){
        cout<<"circle!\n";
    }
    else{
        for(auto &e : res){
            cout<<e;
            if(e!=*(res.end()-1))
                cout<<"->";
        }
    }
    return 0;
}
